package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysHomeNavigation;
import com.ruoyi.system.service.ISysHomeNavigationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统首页导航Controller
 *
 * @author ruoyi
 * @date 2020-07-15
 */
@Controller
@RequestMapping("/system/navigation")
public class SysHomeNavigationController extends BaseController {
    private String prefix = "system/navigation";

    @Autowired
    private ISysHomeNavigationService sysHomeNavigationService;

    @RequiresPermissions("system:navigation:view")
    @GetMapping()
    public String navigation() {
        return prefix + "/navigation";
    }

    /**
     * 查询系统首页导航列表
     */
    @RequiresPermissions("system:navigation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysHomeNavigation sysHomeNavigation) {
        startPage();
        List<SysHomeNavigation> list = sysHomeNavigationService.selectSysHomeNavigationList(sysHomeNavigation);
        return getDataTable(list);
    }

    /**
     * 导出系统首页导航列表
     */
    @RequiresPermissions("system:navigation:export")
    @Log(title = "系统首页导航", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysHomeNavigation sysHomeNavigation) {
        List<SysHomeNavigation> list = sysHomeNavigationService.selectSysHomeNavigationList(sysHomeNavigation);
        ExcelUtil<SysHomeNavigation> util = new ExcelUtil<SysHomeNavigation>(SysHomeNavigation.class);
        return util.exportExcel(list, "navigation");
    }

    /**
     * 新增系统首页导航
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存系统首页导航
     */
    @RequiresPermissions("system:navigation:add")
    @Log(title = "系统首页导航", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysHomeNavigation sysHomeNavigation) {
        return toAjax(sysHomeNavigationService.insertSysHomeNavigation(sysHomeNavigation));
    }

    /**
     * 修改系统首页导航
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SysHomeNavigation sysHomeNavigation = sysHomeNavigationService.selectSysHomeNavigationById(id);
        mmap.put("sysHomeNavigation", sysHomeNavigation);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统首页导航
     */
    @RequiresPermissions("system:navigation:edit")
    @Log(title = "系统首页导航", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysHomeNavigation sysHomeNavigation) {
        return toAjax(sysHomeNavigationService.updateSysHomeNavigation(sysHomeNavigation));
    }

    /**
     * 删除系统首页导航
     */
    @RequiresPermissions("system:navigation:remove")
    @Log(title = "系统首页导航", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sysHomeNavigationService.deleteSysHomeNavigationByIds(ids));
    }
}
